# -*- coding: utf-8 -*-

import Formation
import Role
import Strategy

class ThrowIn:
  def apply(self, game):
    pass

class Standard(ThrowIn):
  def __init__(self, shootingPlayer, targetedPlayer, ballLocation, teamPlayer):
    self.shootingPlayer = shootingPlayer
    self.targetedPlayer = targetedPlayer
    self.ballLocation   = ballLocation
    self.teamPlayer     = teamPlayer

  def apply(self, game):
    game.ball.stop()
    game.isThrowingIn = True
    game.ball.location.locate(self.ballLocation)
    self.shootingPlayer.location.locate(game.ball.location)
    self.shootingPlayer.orientation = self.shootingPlayer.location.getDirectionToTake(self.targetedPlayer.location)
    self.shootingPlayer.hasTheBall = True
    game.setBallOwner(self.shootingPlayer)

class BeginTeam1(ThrowIn):
  def apply(self, game):
    if game.ballOwner != None:
      game.ballOwner.hasTheBall = False
      game.setBallOwner(None)
    game.ball.location.locate(game.field.getCenterLocation())
    game.team1.isAttacking = False
    game.team2.isAttacking = False
    game.team1.formation = Formation.Attack(game.field)
    game.team2.formation = Formation.Standard(game.field, True)

    game.team1.applyFormation()
    game.team2.applyFormation()

class BeginTeam2(ThrowIn):
  def apply(self, game):
    if game.ballOwner != None:
      game.ballOwner.hasTheBall = False
      game.setBallOwner(None)
    game.ball.location.locate(game.field.getCenterLocation())
    game.team1.isAttacking = False
    game.team2.isAttacking = False
    game.team1.formation = Formation.Standard(game.field)
    game.team2.formation = Formation.Attack(game.field, True)
    game.team1.applyFormation()
    game.team2.applyFormation()